package Mqsql01;

import Util.DBUtil;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @Author 汤舒青
 * @Version 1.0
 */


public class Mysql05 {
    public static void main(String[] args) {
        Connection con=null;
        PreparedStatement pr=null;
        Scanner input = new Scanner(System.in);
        try {
            con = DBUtil.getConnection();
            String sql="insert into s_student (sname,sex,telephone,qq,wechat,gradeid,enterdate,fromcity,birthday,address,pass,idcardpic)values (?,?,?,?,?,?,?,?,?,?,?,?)";
            System.out.println(sql);
            System.out.println("请输入学生姓名");
            String name = input.next();
            System.out.println("请输入学生性别");
            String sex = input.next();
            System.out.println("请输入学生电话号码");
            String number = input.next();
            System.out.println("请输入学生qq");
            String qq = input.next();
            System.out.println("请输入学生微信");
            String wx = input.next();
            System.out.println("请输入学生年级号");
            int gid = input.nextInt();
            System.out.println("请输入学生入学时间");
            String date = input.next();
            System.out.println("请输入学生来自哪个城市");
            String city = input.next();
            System.out.println("请输入学生生日");
            String bith = input.next();
            System.out.println("请输入学生家庭地址");
            String add = input.next();
            System.out.println("请输入学生密码");
            String pass = input.next();
            System.out.println("请输入学生身份证");
            String cardc = input.next();
             pr = con.prepareStatement(sql);
            pr.setString(1, name);
            pr.setString(2, sex);
            pr.setString(3, number);
            pr.setString(4, qq);
            pr.setString(5, wx);
            pr.setInt(6, gid);
            pr.setDate(7, Date.valueOf(date));
            pr.setString(8, city);
            pr.setDate(9, Date.valueOf(bith));
            pr.setString(10, add);
            pr.setString(11, pass);
            pr.setString(12, cardc);
            int i = pr.executeUpdate();
            if (i > 0) {
                System.out.printf("添加了%d行成功",i);
            } else {
                System.out.println("添加失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(pr);
            DBUtil.close(con);
        }

    }
}
